package file2;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Student extends JFrame implements ActionListener {
    private JTextField tf1,tf2,tf3;
    private JButton bt1;
    private JTable table;
    private JPanel panel1,panel2,panel3;
    Object[] tmprow={"姓名","年龄","地址"};
    DefaultTableModel dtm;

    public Student(){
        setTitle("学生信息表");
        setVisible(true);
        setSize(1000,400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(null);//窗口设置空布局
        JLabel name=new JLabel("姓名");//设置标签
        JLabel age=new JLabel("年龄");
        JLabel addr=new JLabel("地址");
        name.setBounds(50,50,60,25);
        age.setBounds(50,100,60,25);
        addr.setBounds(50,150,60,25);
        add(name);add(age);add(addr);
        tf1=new JTextField();
        tf2=new JTextField();
        tf3=new JTextField();
        tf1.setBounds(110,50,300,25);
        tf2.setBounds(110,100,300,25);
        tf3.setBounds(110,150,300,25);
        add(tf1);add(tf2);add(tf3);
        JButton bt1=new JButton("添加");
        bt1.setBounds(230,200,60,25);
        add(bt1);
        JPanel panel1=new JPanel();
        JLabel n=new JLabel();
        bt1.addActionListener(this);
        table=new JTable();
        dtm=new DefaultTableModel();
        dtm=(DefaultTableModel)table.getModel();
        dtm.setColumnIdentifiers(tmprow);
        JScrollPane scrollPane=new JScrollPane(table);
        add(scrollPane);
//        table.setBounds(420,25,550,300);
//        Object[][] cellData={{"row1-姓名","row1-年龄","row1-地址"},{"row2-姓名","row2-年龄","row2-地址"},{"row1-姓名","row1-年龄","row1-地址"},{"row1-姓名","row1-年龄","row1-地址"},{"row1-姓名","row1-年龄","row1-地址"}};
//        String[] columnNames={"姓名","年龄","地址"};
//        table=new JTable(cellData,columnNames);
//        DefaultTableModel tableModel=(DefaultTableModel)table.getModel();
//        int count=3;
//        tableModel.setColumnCount(count);
//        table.setRowHeight(20);
//        DefaultTableModel tableModel1=(DefaultTableModel)table.getModel();
//        int n=5;
//        tableModel.setColumnCount(n);
//        add(table);
//        table=new JTable();
//        table.setPreferredScrollableViewportSize(new Dimension(550,300));
//        table.setFillsViewportHeight(true);
//        JScrollPane scrollPane=new JScrollPane(table);
//        add(scrollPane);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        String o=e.getActionCommand();
    }

    public static void main(String[] agrs){
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Student();
            }
        });
    }

}
